// Code generated by bpf2go; DO NOT EDIT.
//go:build arm64

package tracer

import (
	"bytes"
	_ "embed"
	"fmt"
	"io"

	"github.com/cilium/ebpf"
)

type bindsnoopBindEvent struct {
	Addr       [16]uint8
	MountNsId  uint64
	Timestamp  uint64
	TsUs       uint64
	Pid        uint32
	BoundDevIf uint32
	Uid        uint32
	Gid        uint32
	Ret        int32
	Port       uint16
	Proto      uint16
	Opts       uint8
	Ver        uint8
	Task       [16]uint8
	_          [6]byte
}

// loadBindsnoop returns the embedded CollectionSpec for bindsnoop.
func loadBindsnoop() (*ebpf.CollectionSpec, error) {
	reader := bytes.NewReader(_BindsnoopBytes)
	spec, err := ebpf.LoadCollectionSpecFromReader(reader)
	if err != nil {
		return nil, fmt.Errorf("can't load bindsnoop: %w", err)
	}

	return spec, err
}

// loadBindsnoopObjects loads bindsnoop and converts it into a struct.
//
// The following types are suitable as obj argument:
//
//	*bindsnoopObjects
//	*bindsnoopPrograms
//	*bindsnoopMaps
//
// See ebpf.CollectionSpec.LoadAndAssign documentation for details.
func loadBindsnoopObjects(obj interface{}, opts *ebpf.CollectionOptions) error {
	spec, err := loadBindsnoop()
	if err != nil {
		return err
	}

	return spec.LoadAndAssign(obj, opts)
}

// bindsnoopSpecs contains maps and programs before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type bindsnoopSpecs struct {
	bindsnoopProgramSpecs
	bindsnoopMapSpecs
}

// bindsnoopSpecs contains programs before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type bindsnoopProgramSpecs struct {
	IgBindIpv4E *ebpf.ProgramSpec `ebpf:"ig_bind_ipv4_e"`
	IgBindIpv4X *ebpf.ProgramSpec `ebpf:"ig_bind_ipv4_x"`
	IgBindIpv6E *ebpf.ProgramSpec `ebpf:"ig_bind_ipv6_e"`
	IgBindIpv6X *ebpf.ProgramSpec `ebpf:"ig_bind_ipv6_x"`
}

// bindsnoopMapSpecs contains maps before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type bindsnoopMapSpecs struct {
	Events               *ebpf.MapSpec `ebpf:"events"`
	GadgetMntnsFilterMap *ebpf.MapSpec `ebpf:"gadget_mntns_filter_map"`
	Ports                *ebpf.MapSpec `ebpf:"ports"`
	Sockets              *ebpf.MapSpec `ebpf:"sockets"`
}

// bindsnoopObjects contains all objects after they have been loaded into the kernel.
//
// It can be passed to loadBindsnoopObjects or ebpf.CollectionSpec.LoadAndAssign.
type bindsnoopObjects struct {
	bindsnoopPrograms
	bindsnoopMaps
}

func (o *bindsnoopObjects) Close() error {
	return _BindsnoopClose(
		&o.bindsnoopPrograms,
		&o.bindsnoopMaps,
	)
}

// bindsnoopMaps contains all maps after they have been loaded into the kernel.
//
// It can be passed to loadBindsnoopObjects or ebpf.CollectionSpec.LoadAndAssign.
type bindsnoopMaps struct {
	Events               *ebpf.Map `ebpf:"events"`
	GadgetMntnsFilterMap *ebpf.Map `ebpf:"gadget_mntns_filter_map"`
	Ports                *ebpf.Map `ebpf:"ports"`
	Sockets              *ebpf.Map `ebpf:"sockets"`
}

func (m *bindsnoopMaps) Close() error {
	return _BindsnoopClose(
		m.Events,
		m.GadgetMntnsFilterMap,
		m.Ports,
		m.Sockets,
	)
}

// bindsnoopPrograms contains all programs after they have been loaded into the kernel.
//
// It can be passed to loadBindsnoopObjects or ebpf.CollectionSpec.LoadAndAssign.
type bindsnoopPrograms struct {
	IgBindIpv4E *ebpf.Program `ebpf:"ig_bind_ipv4_e"`
	IgBindIpv4X *ebpf.Program `ebpf:"ig_bind_ipv4_x"`
	IgBindIpv6E *ebpf.Program `ebpf:"ig_bind_ipv6_e"`
	IgBindIpv6X *ebpf.Program `ebpf:"ig_bind_ipv6_x"`
}

func (p *bindsnoopPrograms) Close() error {
	return _BindsnoopClose(
		p.IgBindIpv4E,
		p.IgBindIpv4X,
		p.IgBindIpv6E,
		p.IgBindIpv6X,
	)
}

func _BindsnoopClose(closers ...io.Closer) error {
	for _, closer := range closers {
		if err := closer.Close(); err != nil {
			return err
		}
	}
	return nil
}

// Do not access this directly.
//
//go:embed bindsnoop_bpfel_arm64.o
var _BindsnoopBytes []byte
